<template>
    <div class="app-container calendar-list-container" v-loading="loading" element-loading-text="正在导出数据">
    <!-- filter 条件查询 -->
    <div class="btn-add">
        <el-button
        icon="el-icon-circle-plus-outline"
        type="button"
        class="el-button el-button--primary"
        @click="addInOrOut"
        >
            新增</el-button
        >
    </div>

    <!-- 新增数据弹窗 -->
    <el-dialog
      title="新增"
      :visible.sync="showAdd"
      @close="showAdd = false"
      width="50%"
    >
        <el-form :model="createForm" :inline="true" ref="createForm" :rules="addRules" label-width="80px">
            <el-form-item label="大类" prop="facilityBarcodeType1" >
              <el-select
                    v-model="createForm.facilityBarcodeType1" 
                    autosize 
                    style="width: 100px"
                    class="ul-item"
                    filterable
                    clearable
                    @focus="getBarcodeType('大类')">
                    <el-option
                        v-for="(item,index) in barcodeType1List"
                        :key="index"
                        :label="item.facilityBarcodeChineseName"
                        :value="item.facilityBarcodeName">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="小类" prop="facilityBarcodeType2" >
              <el-select
              v-model="createForm.facilityBarcodeType2" autosize style="width: 100px"
                    class="ul-item"
                    filterable
                    clearable
                    @focus="getBarcodeType('小类')">
                    <el-option
                        v-for="(item,index) in barcodeType2List"
                        :key="index"
                        :label="item.facilityBarcodeChineseName"
                        :value="item.facilityBarcodeName">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="规格" prop="facilityBarcodeType3" >
              <el-select
              v-model="createForm.facilityBarcodeType3" autosize style="width: 200px"
                    class="ul-item"
                    filterable
                    clearable
                    @focus="getBarcodeType('规格')">
                    <el-option
                        v-for="(item,index) in barcodeType3List"
                        :key="index"
                        :label="item.facilityBarcodeChineseName"
                        :value="item.facilityBarcodeName">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="配置类型" prop="type" >
                <!-- <el-input v-model="createForm.type" autosize style="width: 300px"/> -->
                <el-select
              v-model="createForm.type" autosize style="width: 200px"
                    class="ul-item"
                    filterable
                    clearable>
                    <el-option v-for="(item,index) in typeList" :key="index" :label="item" :value="item">
                    </el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <el-row :gutter="20">
          <el-col :span="6">
            配置项目如下：
          </el-col>
          <el-col :span="6" :offset="12">
            <el-link type="primary">添加配置</el-link>
            <el-button
              @click="addMaintain"
              icon="el-icon-circle-plus-outline"
              class="el-button el-button--primary"
              style="font-size: 15px;margin-left: 20px"
              round></el-button>
          </el-col>
        </el-row>
        <el-form :model="creatForm1" ref="creatForm1" :rules="createRules1">
          <el-table  :data="creatForm1.sonList" v-loading="loadingList" element-loading-text="给我一首歌的时间" stripe border fit highlight-current-row style="width: 100%;margin-top:15px;">
            <el-table-column  label="序号" type="index" align="center" width="80px"/>
            <el-table-column label="代码"  prop="code" align="center">
              <template slot-scope="scope">
                <el-form-item :prop="'creatForm1.sonList.' + scope.$index + '.code'">
                  <el-select @focus="getCodeList" @change="CodeChag($event,scope.$index)" filterable clearable v-model="scope.row.code" style="margin-right: 15px;width: 150px" placeholder="代码">
                    <el-option v-for="(item,index) in codeList" :key="index" :label="item.code" :value="item.code">
                    </el-option>
                  </el-select>
                  <!-- <el-input v-model="scope.row.code"></el-input> -->
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="点检/保养内容"  prop="content" align="center">
              <template slot-scope="scope">
                <el-form-item
                  :prop="'creatForm1.sonList.' + scope.$index + '.content'"
                >
                  <el-input disabled v-model="scope.row.content"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <!-- <el-table-column label="id"  prop="id" align="center">
              <template slot-scope="scope">
                <el-form-item
                  :prop="'creatForm1.sonList.' + scope.$index + '.id'"
                >
                  <el-input disabled v-model="scope.row.id"></el-input>
                </el-form-item>
              </template>
            </el-table-column> -->
            <el-table-column prop="operate" align="center" label="操作" width="100">
              <template slot-scope="scope">
                <div class="fx" style="display: flex">
                  <el-button
                    type="button"
                    icon="el-icon-remove-outline"
                    class="el-button el-button--danger"
                    @click="delson(scope.row,scope.$index)"
                    ></el-button
                  >
                </div>
              </template>
            </el-table-column>
          </el-table>
        </el-form>
        <!-- 公共底部 -->
        <div slot="footer" class="dialog-footer">
            <el-button @click="showAdd = false">取 消</el-button>
            <el-button
            type="primary"
            @click="addfacility('createForm')"
            >新增</el-button
            >
        </div>
    </el-dialog>


    <div class="filter-container">
      <!-- style="width: 150px;margin-right:15px;" -->

        <el-select
            style="margin-right: 15px"
            :style="{ width: inputWid(param.facilityBarcodeType1) }"
            v-model="param.facilityBarcodeType1"
            placeholder="资源大类"
            class="ul-item"
            filterable
            clearable
            @focus="getBarcodeType('大类')">
            <el-option
                v-for="(item,index) in barcodeType1List"
                :key="index"
                :label="item.facilityBarcodeChineseName"
                :value="item.facilityBarcodeName">
            </el-option>
        </el-select>

        <el-select
            style="margin-right: 15px;width: 150px"
            v-model="param.facilityBarcodeType2"
            placeholder="资源小类"
            class="ul-item"
            filterable
            clearable
            @focus="getBarcodeType('小类')">
            <el-option
                v-for="(item,index) in barcodeType2List"
                :key="index"
                :label="item.facilityBarcodeChineseName"
                :value="item.facilityBarcodeName">
            </el-option>
        </el-select>

        <el-select
            style="margin-right: 15px;width: 150px"
            v-model="param.facilityBarcodeType3"
            placeholder="规格型号"
            class="ul-item"
            filterable
            clearable
            @focus="getBarcodeType('规格')">
            <el-option
                v-for="(item,index) in barcodeType3List"
                :key="index"
                :label="item.facilityBarcodeChineseName"
                :value="item.facilityBarcodeName">
            </el-option>
        </el-select>

        <!-- <el-input
            @keyup.enter.native="getData"
            clearable
            style="margin-right: 15px;width: 150px"
            v-model="param.type"
            placeholder="配置类型"
        ></el-input> -->

        <el-select
        v-model="param.type" autosize style="width: 150px"
              class="ul-item"
              placeholder="配置类型"
              filterable
              clearable>
              <el-option v-for="(item,index) in typeList" :key="index" :label="item" :value="item">
              </el-option>
          </el-select>

        <el-input
            @keyup.enter.native="getData"
            clearable
            style="margin-right: 15px;width: 150px"
            v-model="param.jobNumber"
            placeholder="配置人员"
        ></el-input>

        <el-date-picker
          v-model="dateOptions"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          format="yyyy-MM-dd HH:mm:ss"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
          style="margin-right:10px;">
        </el-date-picker>

        <el-button type="primary" v-waves icon="el-icon-search" @click="getData">搜索</el-button>
        <el-button
            type="button"
            v-waves
            class="el-button el-button--warning"
            @click="cancelSubmit"
        >
        重置</el-button>

    </div>

    <!-- table 表格 -->
    <el-table  :data="tableInfo" v-loading="loadingList" element-loading-text="给我一首歌的时间" stripe border fit highlight-current-row style="width: 100%;margin-top:15px;">
      <el-table-column  label="序号" type="index" align="center" width="80px"/>
      <el-table-column label="大类"  prop="facilityBarcodeType1" align="center"/>
      <el-table-column label="小类"  prop="facilityBarcodeType2" align="center"/>
      <el-table-column label="规格型号"  prop="facilityBarcodeType3" align="center"/>
      <el-table-column label="配置类型"  prop="type" align="center"/>
      <el-table-column label="点检项目代码"  prop="code" align="center"/>
      <el-table-column label="配置人员"  prop="jobNumber" align="center"/>
      <el-table-column label="修改时间"  prop="updateTime" align="center"/>
      <el-table-column label="操作" fixed="right" align="center" width="130">
            <template slot-scope="scope" >
                <div class="fx" style="display: flex">
                    <el-button size="mini" type="primary" @click="handleEdit(scope.row)">修改</el-button>
                    <el-button
                        icon="el-icon-delete"
                        class="el-button el-button--danger"
                        style="font-size: 15px;"
                        @click="handleDelete(scope.row,scope.$index)"
                    ></el-button>
                </div>
            </template>
      </el-table-column>
    </el-table>

    <!-- 修改数据弹窗 -->
    <el-dialog
      title="修改工序信息"
      :visible.sync="showupd"
      @close="showupd = false"
      width="50%"
    >
        <el-form :model="updForm" :inline="true" ref="updForm" :rules="addRules" label-width="80px">
            <el-form-item label="大类" prop="facilityBarcodeType1" >
              <el-select
              v-model="updForm.facilityBarcodeType1" autosize style="width: 100px"
                    class="ul-item"
                    filterable
                    clearable
                    @focus="getBarcodeType('大类')">
                    <el-option
                        v-for="(item,index) in barcodeType1List"
                        :key="index"
                        :label="item.facilityBarcodeChineseName"
                        :value="item.facilityBarcodeName">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="小类" prop="facilityBarcodeType2" >
              <el-select
              v-model="updForm.facilityBarcodeType2" autosize style="width: 100px"
                    class="ul-item"
                    filterable
                    clearable
                    @focus="getBarcodeType('小类')">
                    <el-option
                        v-for="(item,index) in barcodeType2List"
                        :key="index"
                        :label="item.facilityBarcodeChineseName"
                        :value="item.facilityBarcodeName">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="规格" prop="facilityBarcodeType3" >
              <el-select
              v-model="updForm.facilityBarcodeType3" autosize style="width: 200px"
                    class="ul-item"
                    filterable
                    clearable
                    @focus="getBarcodeType('规格')">
                    <el-option
                        v-for="(item,index) in barcodeType3List"
                        :key="index"
                        :label="item.facilityBarcodeChineseName"
                        :value="item.facilityBarcodeName">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="配置类型" prop="type" >
                <el-select
              v-model="updForm.type" autosize style="width: 200px"
                    class="ul-item"
                    filterable
                    clearable>
                    <el-option v-for="(item,index) in typeList" :key="index" :label="item" :value="item">
                    </el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <el-row :gutter="20">
          <el-col :span="6">
            配置项目如下：
          </el-col>
          <el-col :span="6" :offset="12">
            <el-link type="primary">添加配置</el-link>
            <el-button
              @click="addMaintain"
              icon="el-icon-circle-plus-outline"
              class="el-button el-button--primary"
              style="font-size: 15px;margin-left: 20px"
              round></el-button>
          </el-col>
        </el-row>
        <el-form :model="creatForm1" ref="creatForm1" :rules="createRules1">
          <el-table  :data="creatForm1.sonList" v-loading="loadingList" element-loading-text="给我一首歌的时间" stripe border fit highlight-current-row style="width: 100%;margin-top:15px;">
            <el-table-column  label="序号" type="index" align="center" width="80px"/>
            <el-table-column label="代码"  prop="code" align="center">
              <template slot-scope="scope">
                <el-form-item :prop="'creatForm1.sonList.' + scope.$index + '.code'">
                <el-select @focus="getCodeList" @change="CodeChag($event,scope.$index)" filterable clearable v-model="scope.row.code" style="margin-right: 15px;width: 150px" placeholder="代码">
                    <el-option v-for="(item,index) in codeList" :key="index" :label="item.code" :value="item.code">
                    </el-option>
                  </el-select>
                  <!-- <el-input v-model="scope.row.code"></el-input> -->
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="点检/保养内容"  prop="content" align="center">
              <template slot-scope="scope">
                <el-form-item
                  :prop="'creatForm1.sonList.' + scope.$index + '.content'"
                >
                  <el-input disabled v-model="scope.row.content"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <!-- <el-table-column label="id"  prop="id" align="center">
              <template slot-scope="scope">
                <el-form-item
                  :prop="'creatForm1.sonList.' + scope.$index + '.id'"
                >
                  <el-input disabled v-model="scope.row.id"></el-input>
                </el-form-item>
              </template>
            </el-table-column> -->
            <el-table-column prop="operate" align="center" label="操作" width="100">
              <template slot-scope="scope">
                <div class="fx" style="display: flex">
                  <el-button
                    type="button"
                    icon="el-icon-remove-outline"
                    class="el-button el-button--danger"
                    @click="delson(scope.row,scope.$index)"
                    ></el-button
                  >
                </div>
              </template>
            </el-table-column>
          </el-table>
        </el-form>

        <!-- 公共底部 -->
        <div slot="footer" class="dialog-footer">
            <el-button @click="showupd = false">取 消</el-button>
            <el-button
            type="primary"
            @click="updprocess('updForm')"
            >修改</el-button
            >
        </div>
    </el-dialog>

   <!-- pagination 分页 -->
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="listQuery.page"
        :page-sizes="[5,10, 20, 30, 40, 100, 300, 500]"
        :page-size="listQuery.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>

    <el-divider></el-divider>

    <el-button style="margin-right: 10px" type="success" size="small" @click="hExportExcel">导出数据Excel</el-button>

  </div>
</template>

<script>
import { resourceFind,onfigurationAdd,resourceUpd,resourceDel,selbarcodeType,resourcefindInfo,configurationFind } from "@/api/processRoute"
import { getCenter } from '../../api/workSection.js'
export default {
    name: 'maintenanceConfiguration',
    data () {
        return {
          codeList: [],
          creatForm1:{sonList:[]},
            listQuery: {
                page: 1,                                    //页码
                limit: 10                                   //每页多少条记录
            },
            param: {
                code: '',                      
                content: ''                    
            },
            total: 0,                                      //数据的总数
            tableInfo: [],
            tablePZ:[],
            showMX: false,
            loadingList: false,
            loading: false,
            centerList: [],                         //工作中心列表
            createForm: {},
            typeList: ['设备点检', '设备保养'],
            updForm: {},
            dateOptions: this.getNowTime(),
            props: { multiple: true },
            // 表单校验
            addRules: {
              facilityBarcodeType1: [
                    { required: true, message: "大类不能为空!", trigger: "change" },
                ],
                facilityBarcodeType2: [
                    { required: true, message: "小类不能为空!", trigger: "change" },
                ],
                facilityBarcodeType3: [
                    { required: true, message: "规格不能为空!", trigger: "change" },
                ],
                type: [
                    { required: true, message: "配置类型", trigger: "change" },
                ],
                facilityBarcodeType2: [
                    { required: true, message: "小类不能为空!", trigger: "change" },
                ],
            },
            pickerOptions: {                            // 选择时间范围
              shortcuts: [{
                text: '最近一周',
                onClick(picker) {
                  const end = new Date();
                  const start = new Date();
                  start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                  picker.$emit('pick', [start, end]);
                }
              }, {
                text: '最近一个月',
                onClick(picker) {
                  const end = new Date();
                  const start = new Date();
                  start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                  picker.$emit('pick', [start, end]);
                }
              }, {
                text: '最近三个月',
                onClick(picker) {
                  const end = new Date();
                  const start = new Date();
                  start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                  picker.$emit('pick', [start, end]);
                }
              }]
            },
            createRules1: {
              code: [
                { required: true, message: "请输入代码", trigger: "change" },
              ],
              content: [
                { required: true, message: "请输入点检内容", trigger: "change" },
              ]
            },
            showAdd: false,
            showupd: false,
            userInfo: this.$store.state.user.userInfo,
            barcodeType1List: [],
            accessTypeList: ['出库','入库'],
            barcodeType2List: [],
            barcodeType3List: []
        }
    },
    computed: {
      inputWid() {
        return function (value) {
            if(!value || (value.length <= 10)){
              return '150px'
            } else {
              return (150 + (String(value).length-10)*6) + 'px'
            }
        }
      }
    },
    methods: {
        getData(){
          this.listQuery.page = 1
          this.listQuery.limit = 10
          this.handleFilter()
        },
        async handleFilter() {
            this.loadingList = true
            let query = Object.assign({},this.listQuery,this.param)
            if(this.dateOptions) {
              if(this.dateOptions.length) {
                  query.strTime = this.dateOptions[0]
                  query.endTime = this.dateOptions[1]
              }
            }
            let data = await resourceFind(query)
            let errmsg = data.msg
            this.loadingList = false
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errmsg)
            this.total = data.data.count
            this.tableInfo = data.data.list
        },
        // 获取代码
        async getCodeList(){
          let query = {
            page:1,
            limit: 10000
          }
          const res = await configurationFind(query)
          this.codeList = res.data.list
        },
        async getBarcodeType(type) {
            this.loadingList = true
            let query = {
                facilityBarcodeType: type,
                page: 1,
                limit: 10000
            }
            let data = await selbarcodeType(query)
            let errmsg = data.msg
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errmsg)
            if(type == '大类'){
                this.barcodeType1List = data.data.records
            } else if(type == '小类') {
                this.barcodeType2List = data.data.records
            } else if(type == '规格') {
                this.barcodeType3List = data.data.records
            }
            this.loadingList = false
        },
        // 代码改变
        CodeChag(e,id){
          console.log(e,id)
          this.codeList.forEach(item => {
            if(item.code == e){
              // this.$set(this.codeList[id],'content',item.content)
              this.creatForm1.sonList[id].content = item.content
              this.creatForm1.sonList[id].id = item.id
            }
          })
        },
        // table表单下方的页码组件改变每页显示的数据条数
        handleSizeChange(val) {
          this.listQuery.limit = val
          this.handleFilter()
        },
        // table表单下方的页码组件改变页面
        handleCurrentChange(val) {
          this.listQuery.page = val
          this.handleFilter()
        },
        transformDat(res) {
          const mapInfo = {
            index: '序号',
            facilityBarcodeType1: '大类',
            facilityBarcodeType2: '小类',
            facilityBarcodeType3: '规格型号',
            type: '配置类型',
            code: '点检项目代码',
            jobNumber: '配置人员',
            updateTime: '修改时间',
          }
          // 对data进行格式化
          // 取出所有的属性名
          const props = Object.keys(res[0]) // ['id','']
          // 将属性名从英文转为中文
          const header = props.map(zhkey => mapInfo[zhkey])
          console.log('中文的表头', header)
          // const data=[['xxxx','总裁办'，'13800000']]
          const data = res.map(obj => Object.values(obj))
          return { header, data }
        },
        handleDelete(row,index) {
            this.$confirm('这将会永久删除该行数据，是否继续?', '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.delprocess(row,index)
            }).catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消删除'
                })
            })
        },
        addMaintain(){
          let obj1 = {code:'',content:''}
          this.creatForm1.sonList.push(obj1)
          // if(this.creatForm1.sonList.length){
          //   this.creatForm1.sonList.forEach((item,index) => {
          //     item.idx = index
          //   });
          //   obj1.idx = this.creatForm1.sonList.length
          //   this.creatForm1.sonList.push(obj1)
          // } else {
          //   obj1.idx = 0
          //   this.creatForm1.sonList.push(obj1)
          // }
          // this.creatForm1.sonList.splice(index+1,0,obj)
        },
        delson(row,index){
          this.$confirm('是否确定删除该行?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
              this.creatForm1.sonList.splice(index,1)
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消'
              });          
          });
        },
        async delprocess(row,index){
          let res = await resourceDel({id: row.id})
          if(res.code == '500') return
          if(res.code != '1') return this.$message.error(res.msg)
          this.tableInfo.splice(index,1)
          this.$message.success(res.msg)
        },
         //初始默认执行(重点)，返回日期格式YYYY-MM-DD HH:MM:SS
         getNowTime() {
        let dateTime = +new Date()+8*3600*1000
        const start = new Date(dateTime - 3600 * 1000 * 24 * 7)
            .toISOString()
            .replace('T', ' ')
            .split('.')[0]
            // .substring(0,10) //默认开始时间7天前
        const end = new Date(dateTime)
            .toISOString()
            .replace('T', ' ')
            .split('.')[0]
            // .substring(0,10)//默认结束时间当前时间
        console.log([start, end])
        return [start, end]
        },
        // 导出excel
        async hExportExcel() {
          this.loading = true
          let query = Object.assign({},this.listQuery,this.param)
          query.page = 1
          query.limit = 10000
          if(this.dateOptions) {
              if(this.dateOptions.length) {
                  query.strTime = this.dateOptions[0]
                  query.endTime = this.dateOptions[1]
              }
            }
            let arr = await resourceFind(query)
          if(arr.code == '500') return
          if(arr.code != '1'){
            this.loading = false
            return this.$message.error(errmsg)
          }
          if(!arr.data.list.length){
            this.loading = false
            this.$message.error('暂无数据')
          }
          const { header, data } = this.transformDat(this.setSort(arr.data.list))
          import('@/vendor/Export2Excel').then(excel => {
            // excel表示导入的模块对象
            console.log(excel)
            excel.export_json_to_excel({
            header, // 表头 必填
            data, // 具体数据 必填
            filename: '检点/保养配置', // 文件名称
            autoWidth: true, // 宽度是否自适应
            bookType: 'xlsx' // 生成的文件类型
            })
          })
          this.loading = false
        },
        // 排序函数
        setSort(arr){
          let newArr = JSON.parse(JSON.stringify(arr))
          let arr1 = []
          newArr.forEach((item,index)=>{
            let obj = {
              index: index+1,
              facilityBarcodeType1: item.facilityBarcodeType1,
              facilityBarcodeType2: item.facilityBarcodeType2,
              facilityBarcodeType3: item.facilityBarcodeType3,
              type: item.type,
              code: item.code,
              jobNumber: item.jobNumber,
              updateTime: item.updateTime,
            }
            arr1.push(obj)
          })
          return arr1
        },
        cancelSubmit(){
            this.param = {
                code: '',           
                content: '',      
            }
            this.listQuery.page = 1
            this.handleFilter()
        },
        // 提交表单之前先进行验证
        addfacility(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.submitprocess()
                } else {
                    return false
                }
            })
        },
        async submitprocess(){
            let query = Object.assign({},this.createForm)
            if(this.creatForm1.sonList.length ){
              query.code = this.creatForm1.sonList.map(obj => obj['code']).join(',');
              query.emsFacilityMaintenanceItemConfigurationId = this.creatForm1.sonList.map(obj => obj['id']).join(',');
            }
            const data = await onfigurationAdd(query)
            const errMsg = data.msg
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errMsg)
            this.$message.success(errMsg)
            this.resetForm()
            this.showAdd = false
            this.handleFilter()
        },
        resetForm(){
             this.$refs.createForm.resetFields();
        },
        async handleEdit(row){
            let query = {
                id: row.id,
                page: 1,
                limit: 10000
            }
            const res = await resourcefindInfo(query)
            if(res.data.list && res.data.list.length) this.creatForm1.sonList = res.data.list
            this.updForm = Object.assign({},row)
            this.showupd = true
        },
        // 提交表单之前先进行验证
        updprocess(formName) {
            this.$refs[formName].validate((valid) => {  
                if (valid) {
                    this.configurationUpd()
                } else {
                    return false
                }
            })
        },
        async configurationUpd(){
            let query = Object.assign({},this.updForm)
            delete query.createTime
            delete query.updateTime
            if(this.creatForm1.sonList.length ){
              query.code = this.creatForm1.sonList.map(obj => obj['code']).join(',');
              query.emsFacilityMaintenanceItemConfigurationId = this.creatForm1.sonList.map(obj => obj['id']).join(',');
            }
            const data = await resourceUpd(query)
            const errMsg = data.msg
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errMsg)
            this.showupd = false
            this.handleFilter()
            this.$message.success(errMsg)
        },
        addInOrOut(){
            this.creatForm1.sonList = [{code:'',content:''}]
            this.showAdd = true
        },
    },
    // 进入页面获取table信息
    mounted() {
        this.handleFilter()
    }
}
</script>

<style>

.btn-add{
    margin-bottom: 28px;
}

.ul-item{
  width: 85%;
}
</style>
